using ChikovMF.Context;
using Microsoft.EntityFrameworkCore;

namespace ChikovMF.Tests
{
    public class ChikovMFContextFactory
    {
        public static ChikovMFContext Create()
        {
            var options = new DbContextOptionsBuilder<ChikovMFContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            var context = new ChikovMFContext(options);
            context.Database.EnsureCreated();

            context.Tags.AddRange(
                new Entities.Tag
                {
                    Name = "tag1",
                    TagId = Guid.Parse("a3446f5d-5e34-4ae9-aef9-fe0b584bb9cd"),
                },
                new Entities.Tag
                {
                    Name = "tag2",
                    TagId = Guid.Parse("f599072c-1a36-436c-8a2e-b18fdf5bdca2"),
                }
            );

            context.Projects.AddRange(
                new Entities.Project
                {
                    Name = "project1",
                    ProjectId = Guid.Parse("e6e7d3f0-b9b9-4f0b-a9b9-fe0b584bb9cd"),
                    Content = "content1",
                    Description = "description1",
                },
                new Entities.Project
                {
                    Name = "project2",
                    ProjectId = Guid.Parse("d6e7d3f0-b9b9-4f0b-a9b9-fe0b584bb9cd"),
                    Content = "content2",
                    Description = "description2",
                }
            );

            context.SaveChanges();
            return context;
        }

        public static void Destroy(ChikovMFContext context)
        {
            context.Database.EnsureDeleted();
            context.Dispose();
        }
    }
}